<?php

require_once '../model/entity/Amigo.class.php';

$amigo = new Amigo();
$array = $amigo->getNomes($_GET["q"]);
$q = $_GET["q"];
if (strlen($q) > 0) {
    $hint = "";
    for ($i = 0; $i < count($array); $i++) {
        if (strtolower($q) == strtolower(substr($array[$i], 0, strlen($q)))) {
            if ($hint == "") {
                $hint = $array[$i];
            } else {
                $hint = $hint . " , " . $array[$i];
            }
        }
    }
}
if ($hint == "") {
    $response = "Nenhum amigo encontrado...";
} else {
    $response = $hint;
}
//resposta
echo $response;
?>
